/**
 * @author casazaft
 */
Package("xclab.utils").Class("Task",{
	Task:function(config){
		         var pfps = 1 / config.fps;
        var count = Math.floor(config.time / pfps);
        var fn = config.fn;
        var taskfn = function(){
            if (count > 0) {
                fn.apply(config);
                count--;
            }
            else {
                clearInterval(config.tid);
				if(config.mutex)config.mutex.running=false;
            }
        };
        this.run = function(){
			if(config.mutex.running)return;
            config.tid = setInterval(taskfn,pfps * 1000);
			config.mutex.running = true;
            return config.tid;
        };
        this.stop = function(){
            clearInterval(config.tid);
			config.mutex.running = false;
        };
    }
});

